<?php
   	include_once "../funciones.php";
        include_once "../validacionPHP/validacion.php";
    validar($_REQUEST);

    $con=conectar();
    $today = date("d-M-Y");

   try {
        $con->beginTransaction();
        $oid=getOIDNuevo('PERSONAS','OID_PER');
        $sql="INSERT INTO PERSONAS VALUES (".$oid.", '".$_REQUEST['DNI']."', '".$_REQUEST['NOMBRE']."', '".$_REQUEST['APELLIDOS']."', '".$_REQUEST['GENERO']."', '".$_REQUEST['FECHA_NAC']."', ".$_REQUEST['PROVINCIA'].", '".$_REQUEST['POBLACION']."', '".$_REQUEST['DIRECCION']."', ".$_REQUEST['TELEFONO_FIJO'].", ".$_REQUEST['TELEFONO_MOVIL'].", '".$_REQUEST['EMAIL']."', 'A12345678', 1)";
        echo $sql;
        $stmt = $con->prepare($sql);
		$stmt->execute();









        switch($_REQUEST['TIPO']){
         case 'VOLUNTARIO':
            $sql="INSERT INTO VOLUNTARIOS VALUES (".$oid.", '".$_REQUEST['CARNET_COND']."', '".$_REQUEST['DATOS_INTERES']."')";
            echo $sql;
            $stmt = $con->prepare($sql);
		    $stmt->execute();
            break;
	    case 'MONITOR':
            $sql="INSERT INTO MONITORES VALUES (".$oid.", '".$_REQUEST['TIPO']."')";
            echo $sql;
            $stmt = $con->prepare($sql);
		    $stmt->execute();
            break;
	    case 'ALUMNO':
            $oidREV=getOIDNuevo('REVISIONES_MEDICAS','OID_REV');
            $sql="INSERT INTO REVISIONES_MEDICAS VALUES (".$oidREV.", '".$_REQUEST['ALERGIAS']."', '".$_REQUEST['LESIONES']."', '".$_REQUEST['ENFERMEDADES']."', '".$_REQUEST['LIMITACIONES']."', '".$_REQUEST['DATOS_INT']."', '".$today."')";
            echo $sql;
            $stmt = $con->prepare($sql);
		    $stmt->execute();
            $sql="INSERT INTO ALUMNOS VALUES (".$oid.", ".$_REQUEST['TALLA_PANT'].", ".$_REQUEST['TALLA_CAMI'].", ".$_REQUEST['TALLA_CALZ'].", ".$oidREV.")";
            echo $sql;
            $stmt = $con->prepare($sql);
		    $stmt->execute();
            break;
	    case 'DELEGADO':
            $sql="INSERT INTO DELEGADOS VALUES (".$oid.", '".$_REQUEST['TIPO']."')";
            echo $sql;
            $stmt = $con->prepare($sql);
		    $stmt->execute();
            break;
        case 'FAMILIAR':
            $sql="INSERT INTO FAMILIARES VALUES (".$oid.", ".$_REQUEST['ALUMNO'].", '".$_REQUEST['PARENTESCO']."', '".$_REQUEST['DATOS_INTERES']."')";
            echo $sql;
            $stmt = $con->prepare($sql);
		    $stmt->execute();
            break;
        }



		$stmt = $con->prepare("commit");
	    $stmt->execute();


	}catch(PDOException $e ) {
			echo "error: ".$e->GetMessage();
            $con->rollBack();
            header( 'Location: insertarPersonas.php?exito=2');
	}

    header( 'Location: insertarPersonas.php?exito=1');

   ?>